Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /** * Mark Notification as Read API Route * * POST /api/notifications/[id]/read */ import { NextRequest, NextResponse } from 'next/server'; import { withAuth, withErrorHandling, successResponse, ApiError, ApiSuccessResponse, } from '@/lib/api'; import { RouteContext } from '@/lib/api/middleware'; import { prisma } from '@/lib/prisma'; import { Session } from 'next-auth'; /** * POST /api/notifications/[id]/read * * Mark a specific notification as read. */ async function handlePost( _request: NextRequest, context: RouteContext | undefined, session: Session ): Promise<NextResponse<ApiSuccessResponse<{ success: boolean }>>> { const userId = session.user.id; const { id } = await (context?.params || {}) as { id?: string }; if (!id) { throw ApiError.validation('Notification ID is required'); } const result = await prisma.notification.updateMany({ where: { id, userId, }, data: { read: true, }, }); if (result.count === 0) { throw ApiError.notFound('Notification'); } return successResponse({ success: true }); } export const POST = withErrorHandling(withAuth(handlePost)); |